# -*- coding: UTF-8 -*-
"""
@Project ：Webpage 
@File    ：app.py
@IDE     ：PyCharm 
@Author  ：于金龙@阿龙的代码在报错
@Date    ：2025/2/19 下午1:50 
"""
from flask import Flask, render_template, request
from flask_mysqldb import MySQL

app = Flask(__name__)

# MySQL 配置
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = '20020115'
app.config['MYSQL_DB'] = 'resume'

mysql = MySQL(app)


@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        search_term = request.form['search_term']
        cur = mysql.connection.cursor()
        query = "SELECT * FROM resume.resume WHERE resume.name LIKE %s OR resume.phone_number LIKE %s"
        pattern = f'%{search_term}%'
        cur.execute(query, (pattern, pattern))
        results = cur.fetchall()
        cur.close()
        return render_template('index.html', results=results, search_term=search_term)
    return render_template('index.html')


if __name__ == '__main__':
    app.run(host='192.168.1.72', debug=True)
